package kuzmenkov.oip.model.dao.hibernate.impl;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.dao.DataAccessException;

import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

import kuzmenkov.oip.model.dao.hibernate.GenericDao;

/**
 * @see kuzmenkov.oip.model.dao.hibernate.GenericDao
 * User: Michael Kuzmenkov
 * Date: 15.03.2009
 * Time: 21:16:21
 */
public class GenericDaoImpl<T, PK extends Serializable> extends HibernateDaoSupport
        implements GenericDao<T, PK> {
    
    private Logger log = Logger.getLogger("global");

    /**
     * Type of a db table
     */
    private Class<T> type;

    /**
     * Sets particular type of a db table
     * @param type
     */
    public void setType (Class<T> type) {
        this.type = type;
    }

    /**
     * @see  kuzmenkov.oip.model.dao.hibernate.GenericDao#create(Object) 
     */
    public PK create(T o) throws DataAccessException{
        return (PK) getHibernateTemplate().save(o);
    }

    /**
     * @see kuzmenkov.oip.model.dao.hibernate.GenericDao#read(java.io.Serializable) 
     */
    public T read(PK id) throws DataAccessException{
        return (T) getHibernateTemplate().load(type, id);
    }

    /**
     * @see kuzmenkov.oip.model.dao.hibernate.GenericDao#update(Object) 
     */
    public void update(T o) throws DataAccessException{
        getHibernateTemplate().update(o);
    }

    /**
     * @see kuzmenkov.oip.model.dao.hibernate.GenericDao#delete(Object) 
     */
    public void delete(T o) throws DataAccessException{
        getHibernateTemplate().delete(o);
    }

}
